package com.jiangnan.receiver;

import com.jiangnan.model.TableData;
import com.jiangnan.queue.PacketQueue;
import com.jiangnan.utils.JTableUtil;
import com.jiangnan.utils.PacketUtil;
import jpcap.packet.Packet;

import javax.swing.table.DefaultTableModel;


/**
 * 接收到packet后的处理动作，将记录插进model
 * @author chenliang
 * @email wschenliang@aliyun.com
 */
public class PacketReceiverImpl implements jpcap.PacketReceiver {

    private static final DefaultTableModel model = JTableUtil.getTableModel();

    @Override
    public void receivePacket(Packet p) {
        if (p == null || p.data == null) {
            return;
        }
        //PacketQueue.enQueue(p);//每接收一个数据包都用于存放
        TableData tableData = PacketUtil.convertPacket2TableData(p);
        model.addRow(tableData.getDataArrays());
    }
}
